<template>
  <div>
    <el-dialog title="车辆调拨" :visible="openTh" @close="cancel" width="800px" destroy-on-close append-to-body>
      <el-form ref="elForm" :model="form" :rules="rules" size="medium" label-width="100px">
        <el-form-item label="车牌号">{{carNo}}</el-form-item>
        <el-form-item label="调拨门店" >{{form.callStoreName|filterNull}}</el-form-item>
        <el-form-item label="调拨时间" >{{form.startTime|filterNull}}</el-form-item>
        <el-form-item label="备注">{{form.remark|filterNull}}</el-form-item>
        <el-divider></el-divider>
        <el-form-item label="调回时间" prop="endTime">
          <el-date-picker type="datetime" v-model="form.endTime" format="yyyy-MM-dd HH:mm:ss"
                          value-format="yyyy-MM-dd HH:mm:ss" :style="{width: '100%'}" placeholder="请选择调回时间" clearable>
          </el-date-picker>
        </el-form-item>

        <el-form-item label="备注" prop="remark">
          <el-input v-model="remark" type="textarea" placeholder="请输入备注" :maxlength="50"
                    show-word-limit :autosize="{minRows: 2, maxRows: 3}" :style="{width: '100%'}"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="handelConfirm">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {
  getInfoBycarId,
  updateSecondment,
} from "@/api/car/secondment";
export default {
  inheritAttrs: false,
  components: {
  },
  props: {
    carId: {
      type: String,
      default: ''
    },
    carNo: {
      type: String,
      default: ''
    },
    openTh: {
      type: Boolean,
      default: false
    },
  },
  data() {
    return {
      remark:"",
      form: {
        carId: undefined,
        carNo: undefined,
        callStore: undefined,
        callStoreName: undefined,
        startTime:null,
        remark:null,
        endTime:null,

      },
      rules: {
        endTime:[{
          required: true,
          message: '请选择调拨时间',
          trigger: 'change'
        }],
      },
    }
  },
  created() {

    getInfoBycarId(this.carId).then(res=>{
      this.form=res.data||{}
      this.form.carNo=this.carNo
      this.form.carId=this.carId
    })
    this.form.carNo=this.carNo
    this.form.carId=this.carId
  },
  mounted() {},
  methods: {
    cancel() {
      this.$emit("close")
    },
    handelConfirm() {
      this.$refs['elForm'].validate(valid => {
        if (valid) {
          this.form.remark=this.form.remark+this.remark
          updateSecondment(this.form).then(response => {
              this.$modal.msgSuccess("操作成功");
              this.$emit("close")
            });
        }
      })
    },
  }
}

</script>
<style>
</style>
